package pt;

/**
 * @author wcj
 * @Date 2021/7/6 22:47
 * @Version 1.0
 */
public class MergeArray {

    /**
     * 合并两个有序数组
     *
     * @param a
     * @param b
     * @return
     */
    public static int[] pt(int[] a, int[] b) {
        int[] helper = new int[a.length + b.length];
        int p1 = 0;
        int p2 = 0;
        int k = 0;
        while (p1 < a.length && p2 < b.length) {
            helper[k++] = a[p1] > b[p2] ? b[p2++] : a[p1++];
        }
        while (p1 < a.length) {
            helper[k++] = a[p1++];
        }
        while (p2 < b.length) {
            helper[k++] = b[p2++];
        }
        return helper;
    }
}
